home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / p_man / cat3 / Socket.Z / Socket
Encoding:
Text File  |  1998-10-28  |  8.1 KB  |  265 lines

  1.  
  2.  
  3.  
  4.      SSSSoooocccckkkkeeeetttt((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))         SSSSoooocccckkkkeeeetttt((((3333))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       Socket, sockaddr_in, sockaddr_un, inet_aton, inet_ntoa -
  10.       load the C socket.h defines and structure manipulators
  11.  
  12.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  13.           use Socket;
  14.  
  15.           $proto = getprotobyname('udp');
  16.           socket(Socket_Handle, PF_INET, SOCK_DGRAM, $proto);
  17.           $iaddr = gethostbyname('hishost.com');
  18.           $port = getservbyname('time', 'udp');
  19.           $sin = sockaddr_in($port,    $iaddr);
  20.           send(Socket_Handle, 0, 0,    $sin);
  21.  
  22.           $proto = getprotobyname('tcp');
  23.           socket(Socket_Handle, PF_INET, SOCK_STREAM, $proto);
  24.           $port = getservbyname('smtp', 'tcp');
  25.           $sin = sockaddr_in($port,inet_aton("127.1"));
  26.           $sin = sockaddr_in(7,inet_aton("localhost"));
  27.           $sin = sockaddr_in(7,INADDR_LOOPBACK);
  28.           connect(Socket_Handle,$sin);
  29.  
  30.           ($port, $iaddr) =    sockaddr_in(getpeername(Socket_Handle));
  31.           $peer_host = gethostbyaddr($iaddr, AF_INET);
  32.           $peer_addr = inet_ntoa($iaddr);
  33.  
  34.           $proto = getprotobyname('tcp');
  35.           socket(Socket_Handle, PF_UNIX, SOCK_STREAM, $proto);
  36.           unlink('/tmp/usock');
  37.           $sun = sockaddr_un('/tmp/usock');
  38.           connect(Socket_Handle,$sun);
  39.  
  40.  
  41.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  42.       This module is just a    translation of the C _s_o_c_k_e_t._h file.
  43.       Unlike the old mechanism of requiring    a translated _s_o_c_k_e_t._p_h
  44.       file,    this uses the hhhh2222xxxxssss program (see    the Perl source
  45.       distribution)    and your native    C compiler.  This means    that
  46.       it has a far more likely chance of getting the numbers
  47.       right.  This includes    all of the commonly used pound-defines
  48.       like AF_INET,    SOCK_STREAM, etc.
  49.  
  50.       Also,    some common socket "newline" constants are provided:
  51.       the constants    CR, LF,    and CRLF, as well as $CR, $LF, and
  52.       $CRLF, which map to \015, \012, and \015\012.     If you    do not
  53.       want to use the literal characters in    your programs, then
  54.       use the constants provided here.  They are not exported by
  55.       default, but can be imported individually, and with the
  56.       :crlf    export tag:
  57.  
  58.           use Socket qw(:DEFAULT :crlf);
  59.  
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 10/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      SSSSoooocccckkkkeeeetttt((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))         SSSSoooocccckkkkeeeetttt((((3333))))
  71.  
  72.  
  73.  
  74.       In addition, some structure manipulation functions are
  75.       available:
  76.  
  77.       inet_aton HOSTNAME
  78.            Takes a string giving the name of a host, and
  79.            translates that to the 4-byte string (structure). Takes
  80.            arguments of both the 'rtfm.mit.edu' type and
  81.            '18.181.0.24'. If the host name cannot be resolved,
  82.            returns undef. For multi-homed hosts (hosts with    more
  83.            than one    address), the first address found is returned.
  84.  
  85.       inet_ntoa IP_ADDRESS
  86.            Takes a four byte ip address (as    returned by
  87.            _i_n_e_t__a_t_o_n()) and    translates it into a string of the
  88.            form 'd.d.d.d' where the    'd's are numbers less than 256
  89.            (the normal readable four dotted    number notation    for
  90.            internet    addresses).
  91.  
  92.       INADDR_ANY
  93.            Note: does not return a number, but a packed string.
  94.  
  95.            Returns the 4-byte wildcard ip address which specifies
  96.            any of the hosts    ip addresses. (A particular machine
  97.            can have    more than one ip address, each address
  98.            corresponding to    a particular network interface.    This
  99.            wildcard    address    allows you to bind to all of them
  100.            simultaneously.)     Normally equivalent to
  101.            _i_n_e_t__a_t_o_n('0.0.0.0').
  102.  
  103.       INADDR_BROADCAST
  104.            Note: does not return a number, but a packed string.
  105.  
  106.            Returns the 4-byte 'this-lan' ip    broadcast address.
  107.            This can    be useful for some protocols to    solicit
  108.            information from    all servers on the same    LAN cable.
  109.            Normally    equivalent to _i_n_e_t__a_t_o_n('255.255.255.255').
  110.  
  111.       INADDR_LOOPBACK
  112.            Note - does not return a    number.
  113.  
  114.            Returns the 4-byte loopback address. Normally
  115.            equivalent to _i_n_e_t__a_t_o_n('localhost').
  116.  
  117.       INADDR_NONE
  118.            Note - does not return a    number.
  119.  
  120.            Returns the 4-byte 'invalid' ip address.    Normally
  121.            equivalent to _i_n_e_t__a_t_o_n('255.255.255.255').
  122.  
  123.       sockaddr_in PORT, ADDRESS
  124.  
  125.  
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 10/23/98)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      SSSSoooocccckkkkeeeetttt((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))         SSSSoooocccckkkkeeeetttt((((3333))))
  137.  
  138.  
  139.  
  140.       sockaddr_in SOCKADDR_IN
  141.            In an array context, unpacks its    SOCKADDR_IN argument
  142.            and returns an array consisting of (PORT, ADDRESS).  In
  143.            a scalar    context, packs its (PORT, ADDRESS) arguments
  144.            as a SOCKADDR_IN    and returns it.     If this is confusing,
  145.            use _p_a_c_k__s_o_c_k_a_d_d_r__i_n() and _u_n_p_a_c_k__s_o_c_k_a_d_d_r__i_n()
  146.            explicitly.
  147.  
  148.       pack_sockaddr_in PORT, IP_ADDRESS
  149.            Takes two arguments, a port number and a    4 byte
  150.            IP_ADDRESS (as returned by _i_n_e_t__a_t_o_n()).    Returns    the
  151.            sockaddr_in structure with those    arguments packed in
  152.            with AF_INET filled in.    For internet domain sockets,
  153.            this structure is normally what you need    for the
  154.            arguments in _b_i_n_d(), _c_o_n_n_e_c_t(), and _s_e_n_d(), and is also
  155.            returned    by _g_e_t_p_e_e_r_n_a_m_e(), _g_e_t_s_o_c_k_n_a_m_e()    and _r_e_c_v().
  156.  
  157.       unpack_sockaddr_in SOCKADDR_IN
  158.            Takes a sockaddr_in structure (as returned by
  159.            _p_a_c_k__s_o_c_k_a_d_d_r__i_n()) and returns an array    of two
  160.            elements: the port and the 4-byte ip-address.  Will
  161.            croak if    the structure does not have AF_INET in the
  162.            right place.
  163.  
  164.       sockaddr_un PATHNAME
  165.  
  166.       sockaddr_un SOCKADDR_UN
  167.            In an array context, unpacks its    SOCKADDR_UN argument
  168.            and returns an array consisting of (PATHNAME).  In a
  169.            scalar context, packs its PATHNAME arguments as a
  170.            SOCKADDR_UN and returns it.  If this is confusing, use
  171.            _p_a_c_k__s_o_c_k_a_d_d_r__u_n() and _u_n_p_a_c_k__s_o_c_k_a_d_d_r__u_n() explicitly.
  172.            These are only supported    if your    system has <_s_y_s/_u_n._h>.
  173.  
  174.       pack_sockaddr_un PATH
  175.            Takes one argument, a pathname. Returns the sockaddr_un
  176.            structure with that path    packed in with AF_UNIX filled
  177.            in. For unix domain sockets, this structure is normally
  178.            what you    need for the arguments in _b_i_n_d(), _c_o_n_n_e_c_t(),
  179.            and _s_e_n_d(), and is also returned    by _g_e_t_p_e_e_r_n_a_m_e(),
  180.            _g_e_t_s_o_c_k_n_a_m_e() and _r_e_c_v().
  181.  
  182.       unpack_sockaddr_un SOCKADDR_UN
  183.            Takes a sockaddr_un structure (as returned by
  184.            _p_a_c_k__s_o_c_k_a_d_d_r__u_n()) and returns the pathname.  Will
  185.            croak if    the structure does not have AF_UNIX in the
  186.            right place.
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.      Page 3                        (printed 10/23/98)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      SSSSoooocccckkkkeeeetttt((((3333))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))         SSSSoooocccckkkkeeeetttt((((3333))))
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.      Page 4                        (printed 10/23/98)
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.